//#include <sys/time.h>


#if 0
int main (int argc, char** argv) {
	struct timeval tv = {0};
	int retVal = gettimeofday(&tv, NULL);
	if (0 == retVal) {
		printf("sec:%ld,usec:%ld since 1970-01-01 00:00:00 UTC\n", tv.tv_sec, tv.tv_usec);
	}
	return 0;
}
#endif

#if 0
int main() {
	struct timespec start_time, end_time;
	clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);  // 获取实时时钟时间
	
	int count = 0;
	for(size_t i=0;i<10000;++i){
		++count;
	}
	
	clock_gettime(CLOCK_REALTIME, &end_time);
	long elapsed_ns = (end_time.tv_sec - start_time.tv_sec) * 1000000000 + (end_time.tv_nsec - start_time.tv_nsec);
	printf("Time taken: %ld ns\n", elapsed_ns);
	
	return 0;
}
#endif

#if 0
#include <iostream>
#include <dlfcn.h>

extern "C" {
    typedef unsigned int (*sleep_fun)(unsigned int seconds);
    sleep_fun sleep_f = (sleep_fun)dlsym(RTLD_NEXT,"sleep");

    unsigend int sleep(unsigned int seconds){
        sleep_f(seconds);
        return 0;
    }
};

int main(int argc, char** argv){
    std::cout << "main start ..." << std::endl; 
    sleep(3);
    return 0;
}
#endif

#include <ifaddrs.h>
#include <stdio.h>
#include <arpa/inet.h>

int main() {
    struct ifaddrs *ifaddr, *ifa;
    int family, s;

    if (getifaddrs(&ifaddr) == -1) {
        perror("getifaddrs");
        return 0;
    }

    ifa = ifaddr;
    while (ifa != NULL) {
        printf("%s: %s\n", ifa->ifa_name, (ifa->ifa_addr->sa_family == AF_INET) ? "IPv4" : "IPv6");
		if(ifa->ifa_addr->sa_family == AF_INET){
			sockaddr_in* ipv4 = (sockaddr_in*)ifa->ifa_addr;
			printf("IPv4 Address: %s\n", inet_ntoa(ipv4->sin_addr));
		}
        ifa = ifa->ifa_next;
    }

    freeifaddrs(ifaddr);
    return 1;
}


